package com.xoa.service.equipment.impl;

import com.xoa.dao.common.SysCodeMapper;
import com.xoa.dao.equipment.*;
import com.xoa.model.common.SysCode;
import com.xoa.model.equipment.*;
import com.xoa.model.equipment.LimsEquipReparlogFile;
import com.xoa.model.users.Users;
import com.xoa.service.equipment.EquipReparlogService;
import com.xoa.util.LimsJson;
import com.xoa.util.UserUtil;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class EquipReparlogServicerImpl implements EquipReparlogService {

    @Autowired
    private LimsEquipReparlogMapper limsEquipReparlogMapper;

    @Autowired
    private LimsEquipReparlogFileMapper limsEquipReparlogFileMapper;

    @Autowired
    private LimsEquipExperienceMapper experienceMapper;
    @Autowired
    private LimsCommonCodeMapper limsCommonCodeMapper;

    @Autowired
    private EquipmentMapper equipmentMapper;


    @Autowired
    private EquipTypeMapper equipTypeMapper;

    @Autowired
    private EquipCapyMapper equipCapyMapper;

    @Autowired
    private LimsEquipEventsPlanMapper limsEquipEventsPlanMapper;

    @Autowired
    private SysCodeMapper sysCodeMapper;

    /**
     * 创建作者:   李卫卫
     * 创建日期:   19:54 2019/11/06
     * 方法介绍:    新增设备明细详情信息
     * 参数说明:   No such property: code for class: Script1
     *
     * @return com.xoa.util.LimsJson
     */
    @Override
    public LimsJson<LimsEquipReparlog> addParentLimsEquipReparlog(HttpServletRequest request, LimsEquipReparlog limsEquipReparlog) {
        LimsJson limsJson = new LimsJson(1, "err");
        Users user = UserUtil.getUser(request);
        if (user != null && user.getUserName() != null) {
            limsEquipReparlog.setApplicant(user.getUserName());
        }
        try {
            int i = limsEquipReparlogMapper.insertSelective(limsEquipReparlog);

            if (i > 0) {
                limsJson.setCode(0);
                limsJson.setMsg("添加成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return limsJson;
    }

    /**
     * 创建作者:   李卫卫
     * 创建日期:   19:54 2019/11/06
     * 方法介绍:    删除设备明细详情信息
     * 参数说明:   No such property: code for class: Script1
     *
     * @return com.xoa.util.LimsJson
     */
    @Override
    public LimsJson<LimsEquipReparlog> deleteLimsEquipReparlog(HttpServletRequest request, Integer repalogId) {
        LimsJson limsJson = new LimsJson(1, "err");
        try {
            int i = limsEquipReparlogMapper.deleteByPrimaryKey(repalogId);

            if (i > 0) {//删除成功
                limsJson.setCode(0);
                limsJson.setMsg("删除成功");
            } else {//失败
                limsJson.setCode(1);
                limsJson.setMsg("删除失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return limsJson;
    }

    /**
     * 创建作者:   李卫卫
     * 创建日期:   19:54 2019/11/06
     * 方法介绍:    查看设备明细详情信息
     * 参数说明:   No such property: code for class: Script1
     *
     * @return com.xoa.util.LimsJson
     */
    @Override
    public LimsJson findInvenByDetailId(HttpServletRequest request, Integer repalogId) {
        LimsJson limsJson = new LimsJson(1, "err");
        LimsEquipReparlog limsEquipReparlog = limsEquipReparlogMapper.selectByPrimaryKey(repalogId);

        if (limsEquipReparlog != null) {
            limsJson.setCode(0);
            limsJson.setObj(limsEquipReparlog);
            limsJson.setMsg("查询成功");
        }
        return limsJson;
    }

    /**
     * 创建作者:   李卫卫
     * 创建日期:   19:54 2019/11/06
     * 方法介绍:    根据下拉框条件以及输入参数模糊查询 字段 值
     * 参数说明:   No such property: code for class: Script1
     *
     * @return com.xoa.util.LimsJson
     */
    @Override
    public LimsJson<LimsEquipReparlog> selectExperienceByName(HttpServletRequest request, String fieldName, String fieldValue, Integer page, Integer limit, String repairStatus) {
        LimsJson limsJson = new LimsJson(1, "err");
        List<LimsEquipReparlog> experiencesList = new ArrayList<>();
        Map<String, String> countMap = new HashMap<>();
        Map map = new HashMap();
        int count = 0;
        PageParams pageParams = new PageParams();
        pageParams.setUseFlag(true);  //启动分页
        pageParams.setPage(Integer.valueOf(request.getParameter("page")));//当前页数
        pageParams.setPageSize(Integer.valueOf(limit)); //每页限制条数
        map.put("pageParams", pageParams);
        if ("REPALOG_ID".equals(fieldName)) {
            map.put("fieldName", "REPALOG_ID");
        }
        if ("EQUIP_NAME".equals(fieldName)) {
            map.put("fieldName", "EQUIP_NAME");
        }
        if ("EQUIP_TYPE_NAME".equals(fieldName)) {
            map.put("fieldName", "EQUIP_TYPE_NAME");
        }
        if ("FAULT_TYPE".equals(fieldName)) {
            map.put("fieldName", "FAULT_TYPE");
        }
        if ("FAULT_POSITION".equals(fieldName)) {
            map.put("fieldName", "FAULT_POSITION");
        }
        if ("FAULTDESC".equals(fieldName)) {
            map.put("fieldName", "FAULTDESC");
        }
        if ("APPLICANT".equals(fieldName)) {
            map.put("fieldName", "APPLICANT");
        }
        if ("WORTKFLOW_NO".equals(fieldName)) {
            map.put("fieldName", "WORTKFLOW_NO");
        }
        map.put("fieldValue", fieldValue);
        experiencesList = limsEquipReparlogMapper.selectEquipExperienceByName(map);
        count = pageParams.getTotal();
        if (experiencesList.size() > 0) {
            limsJson.setCount(count);
            limsJson.setMsg("查询成功");
            limsJson.setCode(0);
            limsJson.setData(experiencesList);
        } else {
            limsJson.setMsg("暂无数据");
        }
        return limsJson;
    }


    /**
     * 创建作者:   李卫卫
     * 创建日期:   19:54 2019/11/07
     * 方法介绍:     查询全部数据分页
     * 参数说明:   No such property: code for class: Script1
     *
     * @return com.xoa.util.LimsJson
     */
    @Override
    public LimsJson<LimsEquipReparlog> selectEquipReparlog(HttpServletRequest request, Integer page, Integer limit) {
        LimsJson limsJson = new LimsJson(1, "err");
        Map map = new HashMap();
        int count = 0;
        //封装分页参数
        PageParams pageParams = new PageParams();
        pageParams.setUseFlag(true);  //启动分页
        pageParams.setPage(Integer.valueOf(request.getParameter("page")));//当前页数
        pageParams.setPageSize(Integer.valueOf(limit));//每页限制条数
        map.put("pageParams", pageParams);
        List<LimsEquipReparlog> limsEquipReparlogs = limsEquipReparlogMapper.selectEquipReparlogByAll(map);
        if (limsEquipReparlogs.size() > 0) {
            count = limsEquipReparlogMapper.countAllExperience();
            limsJson.setCount(count);
            limsJson.setCode(0);
            limsJson.setData(limsEquipReparlogs);
            limsJson.setMsg("查询成功");
        } else {
            limsJson.setMsg("查询无数据");
        }

        return limsJson;


    }

    /**
     * 创建作者:   李卫卫
     * 创建日期:   19:54 2019/11/07
     * 方法介绍:    根据id修改设备状态
     * 参数说明:   No such property: code for class: Script1
     *
     * @return com.xoa.util.LimsJson
     */

    @Override
    public LimsJson updateByEquipReparlog(HttpServletRequest request, String repairStatus, String equipStatuasCode, Integer repalogId) {
        LimsJson limsJson = new LimsJson(1, "err");
        int count = 0;
        LimsEquipReparlog limsEquipReparlog = limsEquipReparlogMapper.selectReparlog(repalogId);
        if (limsEquipReparlog != null) {
            Map map = new HashMap();
            map.put("repairStatus", repairStatus);//  维修状态
            map.put("repalogId", repalogId);
            map.put("equipStatuasCode", equipStatuasCode);// 设备状态  Code码 EQUIP_OCCUPY
            count = limsEquipReparlogMapper.updateByExampleSelectives(map);
        }
        if (count > 0) {
            limsJson.setCode(0);
            limsJson.setMsg("修改成功");
        } else {
            limsJson.setCode(1);
            limsJson.setMsg("修改失败");
        }

        return limsJson;
    }


    /**
     * 创建作者:   李卫卫
     * 创建日期:   19:54 2019/11/07
     * 方法介绍:    新增设备的故障信息
     * 参数说明:   No such property: code for class: Script1
     *
     * @return com.xoa.util.LimsJson
     */

    @Override
    public LimsJson<LimsEquipReparlog> insertEquipReparlog(HttpServletRequest request, LimsEquipReparlog limsEquipReparlog, String attachId, String attachName) {
        LimsJson limsJson = new LimsJson(1, "err");
        try {
            String userName = UserUtil.getUser(request).getUserName(); //系统管理员
            Date date = new Date();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String format = formatter.format(date);  //当前时间
            int cont = 0;
            int i = 0;
            limsEquipReparlog.setOutRepairTime(format);//外部诊断时间
            limsEquipReparlog.setInRepairTime(format);//内部诊断时间
            cont = limsEquipReparlogMapper.insertSelective(limsEquipReparlog);
            if (attachId == null || "".equals(attachId) || attachName == null || "".equals(attachName)) {

            } else {
                String[] attIds = attachId.split(",");
                String[] attNames = attachName.split(",");
                for (int k = 0; k < attIds.length; k++) {
                    LimsEquipReparlogFile limsEquipReparlogFile = new LimsEquipReparlogFile();
                    limsEquipReparlogFile.setUpdateName(date); //上传时间
                    limsEquipReparlogFile.setAttachmentId(String.valueOf(attIds[i]));//文件地址
                    limsEquipReparlogFile.setAttachmentName(attNames[i]);//附件名称
                    limsEquipReparlogFile.setUpdateUser(userName);//添加人 系统管理员
                    limsEquipReparlogFile.setRepalogId(limsEquipReparlog.getRepalogId());//设备id
                    String attName = attNames[i].toLowerCase();
                    if (attName.indexOf(".jpg") != -1 || attName.indexOf(".png") != -1 || attName.indexOf(".pdf") != -1 || attName.indexOf(".jpeg") != -1) {
                        limsEquipReparlogFile.setFileType("1");
                    } else {
                        limsEquipReparlogFile.setFileType("2");
                    }
                    i += limsEquipReparlogFileMapper.insertSelective(limsEquipReparlogFile);
                }

            }
            if (cont > 0 || i > 0) {
                limsJson.setCode(0);
                limsJson.setMsg("添加成功");
            } else {
                limsJson.setCode(1);
                limsJson.setMsg("添加失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return limsJson;
    }

    /**
     * 创建作者:   李卫卫
     * 创建日期:   19:54 2019/11/07
     * 方法介绍:    修改 根据设备id修改页面的基本数据信息
     * 参数说明:   No such property: code for class: Script1
     *
     * @return com.xoa.util.LimsJson
     */

    @Override
    public LimsJson updateEquipReparlog(HttpServletRequest request, LimsEquipReparlog equipReparlog, String attachId, String attachName) {
        LimsJson limsJson = new LimsJson(1, "err");
        LimsEquipReparlog limsEquipReparlog = limsEquipReparlogMapper.selectByPrimaryKey(equipReparlog.getRepalogId());
        if (limsEquipReparlog != null) {
            String userName = UserUtil.getUser(request).getUserName(); //系统管理员
            Date date = new Date();
            int j = 0;
            if (attachId != null && !"".equals(attachId)) {
                String[] attachid = attachId.split(",");
                String[] attachname = attachName.split(",");
                for (int i = 0; attachId.length() > i; i++) {  //遍历出来
                    String attId = attachid[i];
                    String attName = attachname[i];         //根据 附件名字 和id查询
                    LimsEquipReparlogFile limsEquipReparlogFile1 = limsEquipReparlogFileMapper.selectAllReparlogFile(attName, attId);
                    if (limsEquipReparlogFile1 == null) {
                        LimsEquipReparlogFile limsEquipReparlogFile = new LimsEquipReparlogFile();
                        limsEquipReparlogFile.setUpdateUser(userName);  //系统管理员
                        limsEquipReparlogFile.setUpdateName(date);// 上传时间
                        limsEquipReparlogFile.setAttachmentId(attId);//附件id
                        limsEquipReparlogFile.setAttachmentName(attName);//附件名称
                        limsEquipReparlogFile.setRepalogId(limsEquipReparlog.getRepalogId());//附件id
                        j += limsEquipReparlogFileMapper.insertSelective(limsEquipReparlogFile); //添加接口
                    }
                }
            }
            int count = limsEquipReparlogMapper.updateByPrimaryKeySelective(equipReparlog);//修改设备料接口
            if (count > 0 || j > 0) {
                limsJson.setCode(0);
                limsJson.setMsg("修改成功");
            } else {
                limsJson.setCode(1);
                limsJson.setMsg("修改失败");
            }
        } else {
            limsJson.setMsg("参数无效");
        }
        return limsJson;
    }


    /**
     * 创建作者:   李卫卫
     * 创建日期:   19:54 2019/11/08
     * 方法介绍:   根据设备状态查询信息  @
     * 参数说明:   No such property: code for class: Script1
     *
     * @return com.xoa.util.LimsJson
     */
    @Override
    public LimsJson selectEquipReparlogs(HttpServletRequest request, String repairStatus, Integer page, Integer limit) {
        LimsJson limsJson = new LimsJson(1, "err");
        Map map = new HashMap();
        int count = 0;
        //封装分页参数
        PageParams pageParams = new PageParams();
        pageParams.setUseFlag(true);  //启动分页
        pageParams.setPage(Integer.valueOf(request.getParameter("page")));//当前页数
        pageParams.setPageSize(Integer.valueOf(limit));//每页限制条数
        map.put("pageParams", pageParams);
        map.put("repairStatus", repairStatus);
        List<LimsEquipReparlog> limsEquipReparlogs = limsEquipReparlogMapper.selectEquipReparlogs(map);
        if (limsEquipReparlogs.size() > 0) {
            limsJson.setCount(pageParams.getTotal());//返回分页总数
            limsJson.setCode(0);
            limsJson.setData(limsEquipReparlogs);
            limsJson.setMsg("查询成功");

        } else {
            limsJson.setMsg("暂无数据");
        }
        return limsJson;
    }

    @Override
    public LimsJson updateByPrimaryKeySelective(HttpServletRequest request, LimsEquipReparlog limsEquipReparlog) {
        LimsJson limsJson = new LimsJson(1, "err");
        int cont = 0;
        cont = limsEquipReparlogMapper.updateByPrimaryKeySelective(limsEquipReparlog);
        if (cont > 0) {
            limsJson.setCode(0);
            limsJson.setMsg("成功");
        } else {
            limsJson.setMsg("失败");
        }
        return limsJson;
    }

    /**
     * @return limsJson
     * @作者 李卫卫
     * @创建日期 20:07 2019/11/27
     * @类介绍 编辑按钮查询全部
     * @参数
     */

    @Override
    public LimsJson selectByPrimaryKey(HttpServletRequest request, Integer repalogId) {
        LimsJson limsJson = new LimsJson(1, "err");
        Map map = new HashMap();
        List<LimsEquipReparlog> limsEquipReparlogs = limsEquipReparlogMapper.selectByPrimary(repalogId);//设备维修查询全部
        List<LimsEquipReparlogFile> limsEquipReparlogFiles = limsEquipReparlogFileMapper.selectAllReparlog(repalogId);//根据id查询附件
        if (limsEquipReparlogs.size() > 0) { //判断设备长度是否大于0
            for (LimsEquipReparlog reparlog : limsEquipReparlogs) {  //遍历设备数据
                if (reparlog.getFaultType() != null || !"".equals(reparlog.getFaultType())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getFaultType());//现象分类
                    if (sysCodes.size() > 0) {
                        reparlog.setFaultType(sysCodes.get(0).getCodeName());  //获取  类型名称
                    }
                }
                if (reparlog.getInRepairMode() != null || !"".equals(reparlog.getInRepairMode())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getInRepairMode());//根据Code查询  内部维修方式
                    if (sysCodes.size() > 0) {
                        reparlog.setInRepairMode(sysCodes.get(0).getCodeName());
                    }
                }
                if (reparlog.getInRepairRank() != null || !"".equals(reparlog.getInRepairRank())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getInRepairRank());// 根据Code查询  内部维修等级
                    if (sysCodes.size() > 0) {
                        reparlog.setInRepairRank(sysCodes.get(0).getCodeName());
                    }
                }
                if (reparlog.getOutRepairMode() != null || !"".equals(reparlog.getOutRepairMode())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getOutRepairMode());//根据Code查询   外部维修方式
                    if (sysCodes.size() > 0) {
                        reparlog.setOutRepairMode(sysCodes.get(0).getCodeName());
                    }
                }
                if (reparlog.getOutRepairRank() != null || !"".equals(reparlog.getOutRepairRank())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getOutRepairRank());// 根据Code查询 外部维修等级
                    if (sysCodes.size() > 0) {
                        reparlog.setOutRepairRank(sysCodes.get(0).getCodeName());
                    }
                }
                if (reparlog.getEquipVerifyMode() != null || !"".equals(reparlog.getEquipVerifyMode())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getEquipVerifyMode());//根据Code查询  验证方式
                    if (sysCodes.size() > 0) {
                        reparlog.setEquipVerifyMode(sysCodes.get(0).getCodeName());
                    }
                }
                if (reparlog.getEquipRepairResult() != null || !"".equals(reparlog.getEquipRepairResult())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getEquipRepairResult());// 根据Code查询 验证结果
                    if (sysCodes.size() > 0) {
                        reparlog.setEquipRepairResult(sysCodes.get(0).getCodeName());
                    }
                }
            }
            limsJson.setMsg("查询成功");
            limsJson.setCode(0);
            map.put("limsEquipReparlogFiles", limsEquipReparlogFiles);//附件
            limsJson.setData(limsEquipReparlogs);//设备维修查询全部
            limsJson.setObj(map);
        } else {
            limsJson.setMsg("暂无数据");
        }
        return limsJson;
    }

    /**
     * @return limsJson
     * @作者 李卫卫
     * @创建日期 11:43 2019/12/1
     * @类介绍 根据设备类型查询不同类型数据
     * @参数
     */

    @Override
    public LimsJson selectAllReparlog(Integer equipTypeId, String repairStatus, Integer page, Integer limit) {
        LimsJson limsJson = new LimsJson(1, "err");
        Map map = new HashMap();
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);//当前页数
        pageParams.setPageSize(limit);//每页限制条数
        map.put("pageParams", pageParams);
        map.put("equipTypeId", equipTypeId);
        map.put("repairStatus", repairStatus);
        List<LimsEquipReparlog> limsEquipReparlogs = limsEquipReparlogMapper.selectAllReparlog(map);
        for (LimsEquipReparlog reparlog : limsEquipReparlogs) {
            if (reparlog.getFaultType() != null || !"".equals(reparlog.getFaultType())) {
                List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getFaultType());//现象分类
                if (sysCodes.size() > 0) {
                    reparlog.setFaultType(sysCodes.get(0).getCodeName());
                }
            }
            if (reparlog.getInRepairMode() != null || !"".equals(reparlog.getInRepairMode())) {
                List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getInRepairMode());//内部维修方式
                if (sysCodes.size() > 0) {
                    reparlog.setInRepairMode(sysCodes.get(0).getCodeName());
                }
            }
            if (reparlog.getInRepairRank() != null || !"".equals(reparlog.getInRepairRank())) {
                List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getInRepairRank());//内部维修等级
                if (sysCodes.size() > 0) {
                    reparlog.setInRepairRank(sysCodes.get(0).getCodeName());
                }
            }
            if (reparlog.getOutRepairMode() != null || !"".equals(reparlog.getOutRepairMode())) {
                List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getOutRepairMode());//外部维修方式
                if (sysCodes.size() > 0) {
                    reparlog.setOutRepairMode(sysCodes.get(0).getCodeName());
                }
            }
            if (reparlog.getOutRepairRank() != null || !"".equals(reparlog.getOutRepairRank())) {
                List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getOutRepairRank());//外部维修等级
                if (sysCodes.size() > 0) {
                    reparlog.setOutRepairRank(sysCodes.get(0).getCodeName());
                }
            }
        }
        Integer count = pageParams.getTotal();
        if (limsEquipReparlogs.size() > 0 && limsEquipReparlogs != null) {
            limsJson.setData(limsEquipReparlogs);//查询全部数据
            limsJson.setCount(count);
            limsJson.setMsg("共" + count + "条数据");
            limsJson.setCode(0);
        } else {
            limsJson.setMsg("暂无数据");
        }
        return limsJson;
    }

    /**
     * @return limsJson
     * @作者 李卫卫
     * @创建日期 9:02 2019/12/5
     * @类介绍 根据代码主类型查询故障分类维修方式维修等级
     * @参数
     */
    @Override
    public LimsJson selectAllCommonCode(String parentTyepNo) {
        LimsJson limsJson = new LimsJson(1, "err");
        List<SysCode> sysCodes = sysCodeMapper.selectByCommonCode(parentTyepNo);
        if (sysCodes.size() > 0 && sysCodes != null) {
            limsJson.setMsg("查询成功");
            limsJson.setCode(0);
            limsJson.setData(sysCodes);
        } else {
            limsJson.setMsg("暂无数据");
        }
        return limsJson;
    }

    /**
     * @return limsJson
     * @作者 李卫卫
     * @创建日期 10:38 2019/12/9
     * @类介绍 根据id单独删除附件
     * @参数
     */
    @Override
    public LimsJson deleteByPrimaryKey(Integer fileId) {
        LimsJson limsJson = new LimsJson(1, "err");
        int count = 0;
        count = limsEquipReparlogFileMapper.deleteByPrimaryKey(fileId);
        if (count > 0) {
            limsJson.setMsg("删除成功");
            limsJson.setCode(0);
        } else {
            limsJson.setMsg("删除失败");
        }
        return limsJson;
    }

    /**
     * @return limsJson
     * @作者 李卫卫
     * @创建日期 15:28 2019/12/24
     * @类介绍 根据设备id查询设备记录
     * @参数
     */

    @Override
    public LimsJson selectByequipId(Integer page, Integer limit, LimsEquipReparlog repair, String beginTime, String endTime) {
        LimsJson limsJson = new LimsJson(1, "err");
        List<LimsEquipReparlog> list = null;
        Integer total = null;
        if (repair.getEquipId() == null) {
            limsJson.setMsg("参数无效");
        } else {
            PageParams pageParams = new PageParams();
            Map map = new HashMap();
            pageParams.setPage(page);
            pageParams.setPageSize(limit);
            map.put("repair", repair);
            map.put("beginTime", beginTime);
            map.put("endTime", endTime);
            map.put("pageParams", pageParams);
            list = limsEquipReparlogMapper.selectByequipId(map);
            for (LimsEquipReparlog reparlog : list) {
                if (reparlog.getFaultType() != null || !"".equals(reparlog.getFaultType())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getFaultType());//现象分类
                    if (sysCodes.size() > 0) {
                        reparlog.setFaultType(sysCodes.get(0).getCodeName());
                    }
                }
                if (reparlog.getInRepairMode() != null || !"".equals(reparlog.getInRepairMode())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getInRepairMode());//内部维修方式
                    if (sysCodes.size() > 0) {
                        reparlog.setInRepairMode(sysCodes.get(0).getCodeName());
                    }
                }
                if (reparlog.getInRepairRank() != null || !"".equals(reparlog.getInRepairRank())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getInRepairRank());//内部维修等级
                    if (sysCodes.size() > 0) {
                        reparlog.setInRepairRank(sysCodes.get(0).getCodeName());
                    }
                }
                if (reparlog.getOutRepairMode() != null || !"".equals(reparlog.getOutRepairMode())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getOutRepairMode());//外部维修方式
                    if (sysCodes.size() > 0) {
                        reparlog.setOutRepairMode(sysCodes.get(0).getCodeName());
                    }
                }
                if (reparlog.getOutRepairRank() != null || !"".equals(reparlog.getOutRepairRank())) {
                    List<SysCode> sysCodes = sysCodeMapper.selectAllCommonCode(reparlog.getOutRepairRank());//外部维修等级
                    if (sysCodes.size() > 0) {
                        reparlog.setOutRepairRank(sysCodes.get(0).getCodeName());
                    }
                }
            }
            total = pageParams.getTotal();
        }
        if (list != null) {
            limsJson.setMsg("查询成功");
            limsJson.setCode(0);
            limsJson.setData(list);
            limsJson.setCount(total);
        } else {
            limsJson.setMsg("暂无数据");
        }

        return limsJson;
    }

    /**
     * @return limsJson
     * @作者 杨岩林
     * @创建日期 10:25 2019/11/29
     * @类介绍 根据 所属独立结算组织ID《dep参数tId》和设备类型ID 《equipTypeId》查询数据
     * @
     */

    @Override
    public LimsJson selectEquip(Integer deptId, Integer equipTypeId, Integer page, Integer limit, String columnName, String inputValue, String eventType) {
        LimsJson limsJson = new LimsJson(1, "err");
        try {
            Map map = new HashMap();
            map.put("columnName", columnName);
            map.put("inputValue", inputValue);
            List<EquipType> equipTypeList = equipTypeMapper.selectChildEquipType(equipTypeId);
            map.put("deptId", deptId);

            if (equipTypeList.size() > 0) {
                String ids = "";
                for (EquipType equipType : equipTypeList) {
                    ids = ids + equipType.getId() + ",";
                }
                if (ids.length() > 0) {
                    String[] typeIds = ids.split(",");
                    map.put("typeIds", typeIds);
                }
            } else {
                map.put("equipTypeId", equipTypeId);
            }
            List<Equipment> equipmentList = equipmentMapper.selectAllEqip(map);
            for (Equipment e : equipmentList) {
                if (e.getEquipStatuasId() != null && !e.getEquipStatuasId().equals("")) {
                    EquipCapy equipCapy = equipCapyMapper.selectCommonCodeByTypeNo(e.getEquipStatuasId(),null);
                    if (equipCapy != null && !equipCapy.equals("")) {
                        e.setEquipStatusCode(e.getEquipStatuasId());
                        e.setEquipStatuasId(equipCapy.getCodeTypeName());

                    }
                }
            }
            if (equipmentList != null && equipmentList.size() > 0) {
                List<LimsEquipEventsPlan> limsEquipEventsPlans = limsEquipEventsPlanMapper.queryAll(eventType);
                if (limsEquipEventsPlans != null && limsEquipEventsPlans.size() > 0) {
                    for (LimsEquipEventsPlan limsEquipEventsPlan : limsEquipEventsPlans) {
                        map.put(limsEquipEventsPlan.getEquipId(), limsEquipEventsPlan.getEquipId());
                    }
                    Iterator<Equipment> iterator = equipmentList.iterator();
                    while (iterator.hasNext()) {
                        Integer equipId = iterator.next().getEquipId();
                        if (equipId.equals(map.get(equipId))) {
                            iterator.remove();
                        }
                    }
                }
                List<Equipment> equipmentList2 = this.getPageList(page, limit, equipmentList);
                limsJson.setData(equipmentList2);
                limsJson.setCount(equipmentList.size());
                limsJson.setCode(0);
                limsJson.setMsg("查询成功");
            } else {
                limsJson.setCode(0);
                limsJson.setMsg("暂无数据");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return limsJson;
    }

    //业务层分页 yyl
    public List getPageList(Integer page, Integer limit, List list) {
        List list1 = new ArrayList();
        if (page == 1 && list.size() <= limit) {
            return list;
        } else if (page == 1 && list.size() > limit) {
            for (int i = 0; i < limit; i++) {
                list1.add(list.get(i));
            }
            return list1;

        } else if (page > 1) {
            if (list.size() / limit >= page) {
                for (int i = 0; i < limit; i++) {
                    list1.add(list.get(limit * (page - 1) + i));

                }
                return list1;
            } else {
                for (int i = 0; i < list.size() % 10; i++) {
                    list1.add(list.get(limit * (page - 1) + i));
                }
            }
            return list1;

        } else {
            return null;
        }
    }
}